# load required packages
library(simpleSeg)
# Install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("SydneyBioX/simpleSeg")
simpleSeg provides a structured pipeline for segmentation of cellular tiff stacks and the normalization of features, priming cells for classification / clustering
simpleSeg accepts an image, image list or cytoImageList as input, and generates a CytoImageList of masks as output.
# Reading in sample data
data(pancreasImages)
summary(pancreasImages)
#> [1] "CytoImageList object of length 3 with 2 metadata columns"
The minimum input required is the image/image list and the nuclei marker to be used.
By default, simpleSeg identifies nuclei marker expression using principal component analysis and individual nuclei via watershedding. Nuclei are dilated out by 3 pixels to capture the cytoplasm.
The user may specify the image transformation used using the transform argument.
masks <- simpleSeg(pancreasImages,
transform = c("sqrt"),
watershed = "distance")
display(masks[[1]])
cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1],
blue = 0.03 * pancreasImages[[1]][,,2],
red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)
The measureObjects function from the cytomapper package can then be used to generate a SingleCellExperement object from the images and masks
mcols(masks)$ImageNb <- c("1", "2", "3")
mcols(pancreasImages)$ImageNb <- c("1", "2", "3")
cell.sce <- measureObjects(masks, pancreasImages, img_id = "ImageNb")
The user may specify how watershedding is to be performed. watershed = "distance" (above) performs watershedding on a distance map of the thresholded nuclei signal.
watershed = "combine" (default; below) multiplies this distance map by the raw nuclei marker signal, thus incorporating some information as to the location of the nuclei into the watershedding process.
masks <- simpleSeg(pancreasImages,
nucleus = "H3",
transform = "asinh",
watershed = "combine")
display(masks[[1]])
cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1],
blue = 0.03 * pancreasImages[[1]][,,2],
red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)
The cell body can also be identified in simpleSeg using models of varying complexity, specified with the cellBody argument.
The default and most basic is dilation (cellBody = "dilate"). The size of the dilatation in pixels may be specified with the discDize argument.
masks <- simpleSeg(pancreasImages,
nucleus = "H3",
transform = "asinh",
cellBody = "dilate",
discSize = 3)
display(masks[[1]])
cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1],
blue = 0.03 * pancreasImages[[1]][,,2],
red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)
cellBody = "diskModel uses all the markers to predict the presence of dilated ‘discs’ around the nuclei. The model therefore learns which markers are typically present in the cell cytoplasm and generates a mask based on this.
masks <- simpleSeg(pancreasImages,
nucleus = "H3",
transform = "asinh",
cellBody = "discModel")
display(masks[[1]])
cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1],
blue = 0.03 * pancreasImages[[1]][,,2],
red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)
Finally the user may specify 1 or multiple dedicated cytoplasm markers to predict the cytoplasm. this can be done using cellBody = [marker name] as below.
masks <- simpleSeg(pancreasImages,
nucleus = "H3",
transform = "asinh",
cellBody = "CD8a")
display(masks[[1]])
cells <- rgbImage(green = 0.05 * pancreasImages[[1]][,,1],
blue = 0.03 * pancreasImages[[1]][,,2],
red = 0.05 * pancreasImages[[1]][,,5])
segmented <- paintObjects(masks[[1]], cells, col='#ffffff')
display(segmented)
simpleSeg also supports parallel processing, with the cores argument being used to specify how many cores should be used.
masks <- simpleSeg(pancreasImages, cores = 5)